// pages/withdrawList/withdrawList.js
import request from "../../utils/request";
const app = getApp();
import { areaList } from "../../components/area-data/dist/index.cjs";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    dataList: [],
    pageno: 1,
    combinedObjAll:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getWalletPage();
    this.setData({
      combinedObjAll:Object.assign({}, areaList.city_list, areaList.county_list, areaList.province_list)
    })
  },
  goback() {
    wx.navigateBack({
      delta: 1,
    });
  },
  async getWalletPage() {
    const proxyId = wx.getStorageSync("proxyId");
    const res = await request({
      url:
        app.globalData.baseURL +
        `/app-api/package/trade-order/getOrderProxy?pageNo=${1}&pageSize=${50}&proxyUserId=${proxyId}&payStatus=${1}`,
    });
    const list = res.data.list 
    const datalist = list.map((item) => {
      item.proxyArea = this.data.combinedObjAll[item.proxyArea]
      return item
    })
    this.setData({
      dataList: datalist,
    });
  },
  async onScrollToLower() {
    this.setData({
      pageno: this.data.pageno + 1,
    });
    const res = await request({
      url:
        app.globalData.baseURL +
        `/app-api/package/trade-order/page?pageNo=${
          this.data.pageno
        }&pageSize=${50}`,
      method: "GET",
    });
    const list = res.data.list;
    let datalist = list.map((item) => {
      item.proxyArea = this.data.combinedObjAll[item.proxyArea]
      return item;
    });
    this.setData({
      dataList: this.data.dataList.concat(datalist),
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (options) {
    return {
      title: "嘉之勤官网小程序",
      path: "/pages/index/index",
      imageUrl:
        "https://youyougo2.oss-cn-chengdu.aliyuncs.com/0201506f6fc0f4145e34159c2e2ac66b94b96450dd29e5a19d177edc5dad8023.png",
    };
  },
});
